home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / gfx / fract / FlashMandel.lha / Sources / Modules / Gfx.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  7KB  |  281 lines

  1. /**********************************************************************************************************
  2. **
  3. **  Coded by Dino Papararo     11-Feb-1999
  4. **
  5. **  FUNCTION
  6. **
  7. **    Fade -- perform screen color fading from/to black.
  8. **
  9. **  SYNOPSIS
  10. **
  11. **    BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG TimeDelay,BOOL ToBlack)
  12. **
  13. **  DESCRIPTION
  14. **
  15. **    According with ToBlack value screen will fade from black to PaletteSrc or from PaletteSrc to black.
  16. **
  17. **    MaxStep is number of times colors will be decreased/increased from/to black.
  18. **
  19. **    TimeDelay is the wait time between two palette changes, is necessary for multitasking and faster cpu.
  20. **
  21. **  RETURN
  22. **
  23. **    FALSE if screen proprieties not available or Depth < 2 or MaxStep < 2, TRUE color cycling performed.
  24. **
  25. ***********************************************************************************************************
  26. **
  27. **  Coded by Claudio Pucci & Dino Papararo     26-Oct-1997
  28. **
  29. **  FUNCTION
  30. **
  31. **    Cycle -- perform screen color cycling.
  32. **
  33. **  SYNOPSIS
  34. **
  35. **    BOOL Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  36. **
  37. **  DESCRIPTION
  38. **
  39. **    Function uses a double sized table to manage color cycling.
  40. **
  41. **    So we do not need to save and shift all colors for every cycle,
  42. **
  43. **    but only save and set correct first and last values !
  44. **
  45. **    This function do not load the first four color registers reserved for GUI pens.
  46. **
  47. **  RETURN
  48. **
  49. **    FALSE if screen proprieties not available or Depth < 2, TRUE color cycling performed.
  50. **
  51. **********************************************************************************************************/
  52.  
  53. #include <exec/types.h>
  54. #include <proto/dos.h>
  55. #include <proto/intuition.h>
  56. #include <proto/graphics.h>
  57. #include <proto/gadtools.h>
  58. #include <intuition/intuition.h>
  59. #include <graphics/gfxbase.h>
  60.  
  61. #define RAW_ESC 0x45
  62.  
  63. #define RESERVED_PENS 4L
  64.  
  65. #define BLACK 0L
  66.  
  67. BOOL Fade (struct Window *,ULONG *,ULONG,ULONG,BOOL);
  68. BOOL Cycle (struct Window *,ULONG,BOOL);
  69.  
  70. BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG TimeDelay,BOOL ToBlack)
  71. {
  72. DisplayInfoHandle DHandle;
  73.  
  74. struct DisplayInfo DInfo;
  75.  
  76. static ULONG PaletteTmp [3L * 252L + 2L];
  77.  
  78. LONG Var,Step;
  79.  
  80. ULONG Range,ModeID;
  81.  
  82. BOOL AllBlack;
  83.  
  84.   if ((Win->RPort->BitMap->Depth < 2L) || (MaxStep < 2L)) return FALSE;
  85.  
  86.   ModeID = GetVPModeID (ViewPortAddress (Win));
  87.  
  88.   DHandle = FindDisplayInfo (ModeID);
  89.  
  90.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  91.   {
  92.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE) Range = 32L - 4L;
  93.  
  94.      else Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  95.  
  96.      PaletteTmp [0L] = (Range << 16L) + 4L;
  97.  
  98.      GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&PaletteTmp [1L]);
  99.  
  100.      PaletteTmp [3L * Range + 1L] = NULL;
  101.  
  102.      if (ToBlack)
  103.      {
  104.         for (Step = 0L; Step <= MaxStep; Step++)
  105.         {
  106.             AllBlack = TRUE;
  107.  
  108.             for (Var = 1; Var <= 3L * Range; Var++)
  109.             {
  110.                 if (PaletteTmp [Var])
  111.                 {
  112.                    PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  113.  
  114.                    AllBlack = FALSE;
  115.                 }
  116.             }
  117.  
  118.             if (AllBlack) break;
  119.  
  120.             WaitTOF ();
  121.  
  122.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  123.  
  124.             Delay (TimeDelay);
  125.         }
  126.      }
  127.  
  128.      else
  129.      {
  130.         for (Step = MaxStep; Step >= 0L; Step--)
  131.         {
  132.             for (Var = 1; Var <= 3L * Range; Var++)
  133.  
  134.                 PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  135.  
  136.             WaitTOF ();
  137.  
  138.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  139.  
  140.             Delay (TimeDelay);
  141.         }
  142.  
  143.         LoadRGB32 (ViewPortAddress (Win),PaletteSrc);
  144.      }
  145.  
  146.      return TRUE;
  147.   }
  148.  
  149.   return FALSE;
  150. }
  151.  
  152. BOOL Cycle (struct Window *Win,ULONG TimeDelay,BOOL Left)
  153. {
  154. DisplayInfoHandle DHandle;
  155.  
  156. struct DisplayInfo DInfo;
  157.  
  158. struct IntuiMessage *Message;
  159.  
  160. static ULONG Palette_Tmp [2L * 3L * 252L + 2L];
  161.  
  162. BOOL Loop = TRUE;
  163.  
  164. UWORD MyCode;
  165.  
  166. ULONG MyClass,Counter = NULL,OldBlue,OldRed,Tmp_1,Tmp_2,HalfRange;
  167.  
  168. ULONG ModeID,Range;
  169.  
  170.   if (Win->RPort->BitMap->Depth < 2L) return FALSE;
  171.  
  172.   ModeID = GetVPModeID (ViewPortAddress (Win));
  173.  
  174.   DHandle = FindDisplayInfo (ModeID);
  175.  
  176.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  177.   {
  178.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE)
  179.      {
  180.         Range = 64L - 8L;
  181.  
  182.         HalfRange = Range >> 1L;
  183.  
  184.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [1L]);
  185.  
  186.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * HalfRange + 1L]);
  187.  
  188.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (2L * HalfRange) + 1L]);
  189.  
  190.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (3L * HalfRange) + 1L]);
  191.  
  192.         Palette_Tmp [3L * 2L * (4L * HalfRange) + 1L] = NULL;
  193.      }
  194.  
  195.      else
  196.      {
  197.         Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  198.  
  199.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [1L]);
  200.  
  201.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [3L * Range + 1L]);
  202.  
  203.         Palette_Tmp [2L * 3L * Range + 1L] = NULL;
  204.      }
  205.  
  206.      Palette_Tmp [0L] = (Range << 16L) + 4L;
  207.  
  208.      if (! Left) Counter = Range + 1L;
  209.  
  210.      while (Loop)
  211.      {
  212.            if (Win->UserPort->mp_SigBit)
  213.            {
  214.               if (Message = (struct IntuiMessage *) GT_GetIMsg (Win->UserPort))
  215.               {
  216.                  MyClass = Message->Class;
  217.  
  218.                  MyCode  = Message->Code;
  219.  
  220.                  GT_ReplyIMsg ((struct IntuiMessage *) Message);
  221.  
  222.                  switch (MyClass)
  223.                  {
  224.                     case IDCMP_MOUSEBUTTONS:  if (MyCode == SELECTDOWN) Loop = FALSE;
  225.  
  226.                                               break;
  227.  
  228.                     case IDCMP_MENUPICK    :  Loop = FALSE;
  229.  
  230.                                               break;
  231.  
  232.                     case IDCMP_RAWKEY      :  if (MyCode == RAW_ESC) Loop = FALSE;
  233.  
  234.                                               break;
  235.                  }
  236.               }
  237.            }
  238.  
  239.            if (Left)
  240.            {
  241.               Counter++;
  242.  
  243.               if (Counter > Range) Counter = 1L;
  244.            }
  245.  
  246.            else
  247.            {
  248.               Counter--;
  249.  
  250.               if (Counter < 1L) Counter = Range;
  251.            }
  252.  
  253.            Tmp_1 = 3L * Counter;
  254.  
  255.            Tmp_2 = 3L * (Counter + Range) + 1L;
  256.  
  257.            OldBlue = Palette_Tmp [Tmp_1];
  258.  
  259.            OldRed  = Palette_Tmp [Tmp_2];
  260.  
  261.            Palette_Tmp [Tmp_1] = (Range << 16L) + 4L;
  262.  
  263.            Palette_Tmp [Tmp_2] = NULL;
  264.  
  265.            WaitTOF ();
  266.  
  267.            LoadRGB32 (ViewPortAddress (Win),&Palette_Tmp [3L * Counter]);
  268.  
  269.            Delay (TimeDelay);
  270.  
  271.            Palette_Tmp [Tmp_1] = OldBlue;
  272.  
  273.            Palette_Tmp [Tmp_2] = OldRed;
  274.      }
  275.  
  276.      return TRUE;
  277.   }
  278.  
  279.   return FALSE;
  280. }
  281.